package com.qingke.beSuper2.pojo;

import java.util.ArrayList;
import java.util.List;

import com.qingke.beSuper2.utils.QingkeConsole;

public class Question {

	private long id;
	private String value;
	private int credit;
	private boolean isOpen;
	private Player from;
	private List<Answer> answers = new ArrayList<Answer>();
	private int answerCount;
	
	public Question(){
	}
	
	public Question(long id, String value, int credit, boolean isOpen, Player player) {
		this.id = id;
		this.value = value;
		this.credit = credit;
		this.isOpen = isOpen;
		this.from = player;
	}
	
	public long getId() {
		return id;
	}
	
	public void setId(long id) {
		this.id = id;
	}
	
	public String getValue() {
		return value;
	}
	
	public void setValue(String value) {
		this.value = value;
	}
	
	public int getCredit() {
		return credit;
	}
	
	public void setCredit(int credit) {
		this.credit = credit;
	}
	
	public boolean isOpen() {
		return isOpen;
	}
	
	public void setOpen(boolean isOpen) {
		this.isOpen = isOpen;
	}
	
	public Player getFrom() {
		return from;
	}

	public void setFrom(Player from) {
		this.from = from;
	}
	
	public List<Answer> getAnswers() {
		return answers;
	}
	
	public void setAnswer(List<Answer> answers) {
		this.answers = answers;
	}

	public int getAnswerCount() {
		answerCount = answers.size();
		return answerCount;
	}
	
	public void showAnswers() {
		for (Answer answer: answers) {
			QingkeConsole.println(answer);
		}
	}
	
	public String toString() {
		String template = "[%s] %s: [%s] [%s] [%s]";
		String solvedLabel = isOpen() ? "UNSOLVED" : "SOLVED";
		String unitOfCredit = credit > 1 ? " credits" : " credit";
		String unitOfAnswer = answerCount > 1 ? " answers" : " answer";
		return String.format(template, solvedLabel, id, value, credit + unitOfCredit, answerCount + unitOfAnswer);
	}
}
